package com.nitty.cash.loop.ui.factory

import android.util.SparseArray
import androidx.fragment.app.Fragment
import com.nitty.cash.loop.base.BaseFragment
import com.nitty.cash.loop.ui.fragment.TabMeFragment
import com.nitty.cash.loop.ui.fragment.TabMessageFragment
import com.nitty.cash.loop.ui.fragment.TabRepayFragment
import com.nitty.cash.loop.ui.fragment.TabWithdrawFragment

/**
 * NittyCash
 * @Author wwdeng
 * @CreateTime: 2024/11/28 13:45
 * @Annotation：主页
 */
class NittyTabFactory {

    companion object {
        private val fragments by lazy { SparseArray<BaseFragment?>() }
        @JvmStatic
        fun create(position: Int): Fragment {
            var fragment = fragments.get(position)
            if (fragment == null) {
                fragment = when (position) {
                    0 -> TabWithdrawFragment()
                    1 -> TabRepayFragment()
                    2 -> TabMessageFragment()
                    else -> TabMeFragment()
                }
                fragments.put(position, fragment)
            }
            return fragment
        }

        @JvmStatic
        fun clear() {
            fragments.clear()
        }
    }
}